class Solution {
public:
    string minWindow(string s, string t)
    {
        int hash1[128] = { 0 }, hash2[128] = { 0 };
        int kinds = 0;
        for(auto c : t)
            if(hash1[c]++ == 0) kinds++; // 统计种类

        int minlen = INT_MAX, begin = -1;

        for(int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            if(++hash2[s[right]] == hash1[s[right]]) count++;
            while(count == kinds)
            {
                if(right - left + 1 < minlen)
                {
                    minlen = right - left + 1;
                    begin = left;
                }
                if(hash2[s[left]]-- == hash1[s[left]]) count--;
                left++;
            }
        }
        if(begin == -1) return "";
        return s.substr(begin, minlen);
    }
};